package com.sq.partner.manager.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * 不区分大小写的MAP，使用hashMap实现,Key只能为String
 * @author fshitd04
 * May 31, 2013
 */
public class DBMap implements Map {
	private Map map = new HashMap();
	public void clear() {
		map.clear();
	}
	
	
	public boolean containsKey(Object key) {
		if(key instanceof String){
			return map.containsKey(((String)key).toUpperCase());
		}else{
			throw new IllegalArgumentException("key 只能为String");
		}
	}
	
	public boolean containsValue(Object value) {
		return map.containsValue(value);
	}
	
	public Set entrySet() {
		return map.entrySet();
	}
	
	
	public Object get(Object key) {
		
		if(key instanceof String){
			return map.get(((String)key).toUpperCase());
		}else{
			throw new IllegalArgumentException("key 只能为String");
		}
	}
	
	
	public boolean isEmpty() {
		return map.isEmpty();
	}
	
	
	public Set keySet() {
		return map.keySet();
	}
	
	
	public Object put(Object key, Object value) {
		if(key instanceof String){
			return map.put(((String)key).toUpperCase(),value);
		}else{
			throw new IllegalArgumentException("key只能为String");
		}
	}
	
	
	public void putAll(Map m) {
		for (Iterator i = m.entrySet().iterator(); i.hasNext(); ) {
            Map.Entry e = (Map.Entry) i.next();
            Object key = e.getKey();
            if(key instanceof String){
            	put(((String)key).toUpperCase(), e.getValue());
            }else{
            	throw new IllegalArgumentException("m中含有非String的Key");
            }
            
        }
	
	}
	
	
	public Object remove(Object key) {
		return key instanceof String ? map.remove( ( (String) key).toUpperCase()) : null;
	}
	
	
	public int size() {
		return map.size();
	}
	
	
	public Collection values() {
		return map.values();
	}
	
}
